#1.Prelims ----
library(ggplot2)
library(ggmap)
library(usmap)
library(mapdata)
library(ggthemes)
library(dplyr)
library(RColorBrewer)
library(viridis)
library(maps)
library(cowplot) # for plot_grid() function - good to arrange multiple plots into a grid
library(grid)
library(gridGraphics)
library(patchwork)
library(gridExtra)
library(colorspace)


library(ggpubr)
require(maps)
require(viridis)

theme_set(
  theme_void()
)

theme_set(theme_classic())

#2.Paths ----


BASEPATH="C://Users//wb520443//Dropbox//Research Projects//Global pollution//2_analysis//Replication"


#3.Data ----
#Pollution data
pm_urca<-read.csv(paste0(BASEPATH,"//figdat/urca_pm.csv"), header = TRUE)


urca_pm<-ggplot(pm_urca, aes(urca,pm_round)) +
  geom_raster(aes(fill = count), interpolate = TRUE)+
  geom_line(data=pm_urca, aes(x=urca, y=urca1,z=NULL), 
            size=1,linetype='dashed' , col='grey50' )+
  geom_line(data=pm_urca, aes(x=urca, y=urca2,z=NULL), 
            size=1,linetype='dashed' , col='grey50' )+
  geom_line(data=pm_urca, aes(x=urca, y=urca3,z=NULL), 
            size=1,linetype='dashed' , col='grey50' )+
  geom_segment(x=7.25, xend=7.2,y=0, yend=102,linetype='dotted')+
  geom_segment(x=14.7, xend=14.7,y=0, yend=102,linetype='dotted')+
  annotate(geom = "text", x = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), y = -2, 
           label = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), size = 3) +
  scale_fill_continuous_sequential(palette = 'Oranges', 
                                   na.value = "grey100", 
                                   guide = "none")+
  theme(legend.direction="horizontal", legend.position="bottom",
        legend.margin=margin(-18, 0, 0, 0))+
  theme(text = element_text(size = 20))+ 
  theme(legend.background=element_blank())+
  theme(axis.line.x = element_blank(),
        axis.line.y = element_blank())+
  xlab(element_blank())+
  ylab(element_blank())+
  labs(subtitle = "") +
  theme(plot.subtitle = element_text(size = 30,  hjust = 0.02)) +
  scale_x_continuous(breaks=c(3.5,10.5,22),labels = paste0(c("Urban", "Peri-Urban", "Rural")))+
  scale_y_continuous(breaks=c(0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160))





ggsave(filename = paste0(BASEPATH,"/figures//urca_pm_raster.pdf"), 
       plot = urca_pm,        width = 7,
       height = 4,
       units = c("in"),
       dpi = 300)

